package com.zhihuishu.treenity.service.course.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhihuishu.micro.bbs.openapi.onlineschool.IBBSOpenServiceForOverseaCreateCourse;
import com.zhihuishu.micro.bbs.openapi.onlineschool.dto.OnlinePostModelOpenDto;
import com.zhihuishu.micro.bbs.openapi.remote.RemoteException;
import com.zhihuishu.micro.bbs.openapi.remote.RemoteResult;
import com.zhihuishu.treenity.service.course.BBSCourseService;
@Service("treenityMeetIBBSServiceForOverseaCreateCourse")
public class BBSCourseServiceImpl implements BBSCourseService {

	@Resource
	private IBBSOpenServiceForOverseaCreateCourse bbsCourseService;

	@Override
	public com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> saveModel(OnlinePostModelOpenDto onlinePostModelOpenDto) throws RemoteException {
		RemoteResult<OnlinePostModelOpenDto> result = this.bbsCourseService.saveModel(onlinePostModelOpenDto);
		com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> rs = new com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto>();
		if(result.isSuccess()){
			rs.setResult(result.getResult());
			rs.setSuccess(true);
		}else{
			rs.setResult(null);
			rs.setSuccess(true);
		}
		return rs;
	}

	@Override
	public com.zhihuishu.remote.RemoteResult<Void> deleteModelById(int postId) throws RemoteException {
		com.zhihuishu.remote.RemoteResult<Void> rs = new com.zhihuishu.remote.RemoteResult<Void>();
		RemoteResult<Void> result = this.bbsCourseService.deleteModelById(postId);
		if(result.isSuccess()){			
			rs.setSuccess(true);
		}else{
			rs.setSuccess(false);
		}
		return rs;
	}

	@Override
	public com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> findModelById(int postId) throws RemoteException {
		RemoteResult<OnlinePostModelOpenDto> result = this.bbsCourseService.findModelById(postId);
		com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> rs = new com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto>();
		if(result.isSuccess()){
			rs.setResult(result.getResult());
			rs.setSuccess(true);
		}else{
			rs.setSuccess(false);
			rs.setResult(null);
		}
		return rs;
	}

	@Override
	public com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> updateModel(OnlinePostModelOpenDto onlinePostModelOpenDto) throws RemoteException {
		RemoteResult<OnlinePostModelOpenDto> result = this.bbsCourseService.updateModel(onlinePostModelOpenDto);
		com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto> rs = new com.zhihuishu.remote.RemoteResult<OnlinePostModelOpenDto>();
		if(result.isSuccess()){
			rs.setResult(result.getResult());
			rs.setSuccess(true);
		}else{
			rs.setResult(null);
			rs.setSuccess(true);
		}
		return rs;
	}

	@Override
	public com.zhihuishu.remote.RemoteResult<List<OnlinePostModelOpenDto>> findDiscussListByCourseIdAndChapterId(
			Integer courseId, Integer chapterId) throws RemoteException {
		com.zhihuishu.remote.RemoteResult<List<OnlinePostModelOpenDto>>  result = new com.zhihuishu.remote.RemoteResult<List<OnlinePostModelOpenDto>>();
		RemoteResult<List<OnlinePostModelOpenDto>>     disscussions= bbsCourseService.findDiscussListByCourseIdAndChapterId(courseId, chapterId);
		if(disscussions.isSuccess()){
			 result.setResult(disscussions.getResult());
			 result.setSuccess(true);
		}else{
			 result.setResult(null);
			 result.setSuccess(true);
		}
		return result;
	}

}
